#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2019/4/12  13:57
# @Author: 余浪人
# @email: yulangren520@gmail.com

from wtforms import Form, StringField, validators, SelectField, TextAreaField
from apps.models.column_model import Column_model


class Column_Form(Form):
    def __init__(self, *args, **kwargs):
        super(Column_Form, self).__init__(*args, **kwargs)
        self.column_parent_id.choices = [(r.id, r.column_name) for r in Column_model.query.all()]  # 初始化所属分类
        self.column_parent_id.choices.insert(0, (0, '顶级分类'))

    column_parent_id = SelectField('所属分类', coerce=int)
    column_agree_nav = SelectField('导航', choices=[(1, '显示'), (2, '不显示')], coerce=int)
    column_agree_index = SelectField('首页', choices=[(1, '显示'), (2, '不显示')], coerce=int)
    column_order = StringField('分类权重',validators=[validators.Regexp(r'^\d*$',message='分类权重格式有误!')],default=0, render_kw={"class": "layui-input"})
    column_name = StringField('分类名称', validators=[
        validators.DataRequired('名称不可为空!')],
                              render_kw={"required": "", "class": "layui-input", "style": 'width: 300px;',
                                         "placeholder": '请输入名称'})
    column_keyword = TextAreaField('关键词', render_kw={"class": "layui-textarea", "style": 'width: 340px;'})
    column_description = TextAreaField('分类描述', render_kw={"class": "layui-textarea", "style": 'width: 340px;'})
    column_link = StringField('跳转链接',
                              render_kw={"class": "layui-input", "style": 'width: 300px;', "placeholder": 'http://'})
    # column_color = StringField('栏目背景色',
    #                            render_kw={"class": "layui-input", "style": 'width: 300px;', "placeholder": '#FFF'})


class Column_Edit_Form(Form):
    def __init__(self, *args, **kwargs):
        super(Column_Edit_Form, self).__init__(*args, **kwargs)
        self.column_parent_id.choices = [(r.id, r.column_name) for r in Column_model.query.all()]  # 初始化所属分类
        self.column_parent_id.choices.insert(0,(0, '顶级分类'))

    column_parent_id = SelectField('所属分类', coerce=int)
    column_agree_nav = SelectField('导航', choices=[(1, '显示'), (2, '不显示')], coerce=int)
    column_agree_index = SelectField('首页', choices=[(1, '显示'), (2, '不显示')], coerce=int)
    column_order = StringField('分类权重', validators=[validators.Regexp(r'^\d*$', message='分类权重格式有误!')], default=0,render_kw={"class": "layui-input"})
    column_name = StringField('分类名称', validators=[
        validators.DataRequired('名称不可为空!')],
                              render_kw={"required": "", "class": "layui-input", "style": 'width: 300px;',
                                         "placeholder": '请输入名称'})
    column_keyword = TextAreaField('关键词', render_kw={"class": "layui-textarea", "style": 'width: 340px;'})
    column_description = TextAreaField('分类描述', render_kw={"class": "layui-textarea", "style": 'width: 340px;'})
    column_link = StringField('跳转链接',
                              render_kw={"class": "layui-input", "style": 'width: 300px;', "placeholder": 'http://'})
    # column_color = StringField('栏目背景色',
    #                           render_kw={"class": "layui-input", "style": 'width: 300px;', "placeholder": '#FFF'})
